﻿/*
 * Toast8
 * All rights reserved
 * Copyright (C) 2014 Peter Nylander
 */

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Toast8.Common;

namespace Toast8.SpotifyHelper
{
    public class SpotifyAppHelper
    {
        public static string SpotifyClassName = "SpotifyMainWindow";

        public static void SendCommand(PlayerAppCommand cmd)
        {
            IntPtr hWnd = FindSpotifyMainWindow();

            if (hWnd != IntPtr.Zero)
            {
                APPCOMMAND appCmd = 0;

                switch (cmd)
                {
                    case PlayerAppCommand.Stop:
                        appCmd = APPCOMMAND.APPCOMMAND_MEDIA_STOP;                        
                        break;
                    case PlayerAppCommand.NextTrack:
                        appCmd = APPCOMMAND.APPCOMMAND_MEDIA_NEXTTRACK;                        
                        break;
                    case PlayerAppCommand.PreviousTrack:
                        appCmd = APPCOMMAND.APPCOMMAND_MEDIA_PREVIOUSTRACK;
                        break;
                    case PlayerAppCommand.Mute:
                        appCmd = APPCOMMAND.APPCOMMAND_VOLUME_MUTE;
                        break;
                    case PlayerAppCommand.VolumeUp:
                        appCmd = APPCOMMAND.APPCOMMAND_VOLUME_UP;
                        break;
                    case PlayerAppCommand.VolumeDown:
                        appCmd = APPCOMMAND.APPCOMMAND_VOLUME_DOWN;
                        break;
                    default:
                        return;
                }

                Win32Helper.SendAppCommand(hWnd, appCmd);
            }
            else
            {
                return;
            }
        }

        public static IntPtr FindSpotifyMainWindow()
        {
            return Win32Helper.FindWindow(SpotifyAppHelper.SpotifyClassName, null);
        }

        public static void SetSpotifyWindowInForeground()
        {
            Win32Helper.FindWindowAndFocus(SpotifyAppHelper.SpotifyClassName, null);
        }
        
    }
}
